"
SUnit tests for extensions to SUnit
"
Class {
	#name : 'SUnitExtensionsTest',
	#superclass : 'TestCase',
	#category : 'SUnit-Tests-Core',
	#package : 'SUnit-Tests',
	#tag : 'Core'
}

{ #category : 'history' }
SUnitExtensionsTest class >> lastStoredRun [
	^ ((Dictionary new) add: (#passed->((Set new) add: #testNoExceptionWithMatchingString; add: #testNoExceptionWithNoMatchingString; add: #testExceptionWithMatchingString; add: #testExceptionWithoutMatchingString; add: #testValidShouldNotTakeMoreThan; add: #testInvalidShouldNotTakeMoreThanMilliseconds; add: #testDifferentExceptionInShouldRaiseWithExceptionDo; add: #testShouldRaiseWithExceptionDo; add: #testShouldFix; add: #testAssertionFailedInRaiseWithExceptionDo; add: #testAutoDenyFalse; add: #testAutoDenyTrue; add: #testAutoAssertFalse; add: #testAutoAssertTrue; add: #testValidShouldNotTakeMoreThanMilliseconds; add: #testErrorInRaiseWithExceptionDo; add: #testNoExceptionInShouldRaiseWithExceptionDo; add: #testInvalidShouldNotTakeMoreThan; yourself)); add: (#timeStamp->'22 November 2008 10:11:35 pm'); add: (#failures->((Set new))); add: (#errors->((Set new))); yourself)
]

{ #category : 'real tests' }
SUnitExtensionsTest >> assertionFailedInRaiseWithExceptionDoTest [

	self
		should: [ Error signal ]
		raise: Error
		withExceptionDo: [ :anException | self assert: false ]
]

{ #category : 'real tests' }
SUnitExtensionsTest >> errorInRaiseWithExceptionDoTest [

	self
		should: [ Error  signal ]
		raise: Error
		withExceptionDo: [ :anException | Error signal: 'A forced error' ]
]

{ #category : 'real tests' }
SUnitExtensionsTest >> invalidShouldNotTakeMoreThan [

	self 
		should: [(Delay forMilliseconds: 100) wait] 
		notTakeMoreThanMilliseconds: 50
]

{ #category : 'real tests' }
SUnitExtensionsTest >> invalidShouldNotTakeMoreThanMilliseconds [

	self should: [(Delay forMilliseconds: 100) wait] notTakeMoreThanMilliseconds: 50
]

{ #category : 'testing' }
SUnitExtensionsTest >> isLogging [
	^true
]

{ #category : 'real tests' }
SUnitExtensionsTest >> noExceptionInShouldRaiseWithExceptionDoTest [

	self
		should: [  ]
		raise: Error
		withExceptionDo: [ :anException | Error signal: 'Should not get here' ]
]

{ #category : 'real tests' }
SUnitExtensionsTest >> shouldFixTest [

	self shouldFix: [ Error signal: 'any kind of error' ]
]

{ #category : 'real tests' }
SUnitExtensionsTest >> shouldRaiseWithExceptionDoTest [
	self 
		should: [ Error signal: '1' ] 
		raise: Error withExceptionDo: [ :anException | self assert: anException messageText equals: '1' ]
]

{ #category : 'real tests' }
SUnitExtensionsTest >> shouldRaiseWithSignalDoTest [
	self 
		should: [ Error signal: '1' ] 
		raise: Error withExceptionDo: [ :anException | self assert: anException messageText equals: '1' ]
]

{ #category : 'tests' }
SUnitExtensionsTest >> testAssertionFailedInRaiseWithExceptionDo [
	| testCase testResult |
	testCase := self class selector: #assertionFailedInRaiseWithExceptionDoTest.
	testResult := testCase run.

	self assert: (testResult failures includes: testCase).
	self assert: testResult failures size equals: 1.
	self assertEmpty: testResult passed.
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testAutoAssertFalse [
	
	self assert: self isLogging.
	self 
		should: [ self assert: 1 = 2 description: 'self assert: 1 = 2' ] 
		raise: self defaultTestFailure.
	self 
		assert: (self failureLog contents substrings: {Character cr}) last 
		equals: 'self assert: 1 = 2'.

]

{ #category : 'tests' }
SUnitExtensionsTest >> testAutoAssertTrue [
	self assert: 1 equals: 1.
	self assert: true
]

{ #category : 'tests' }
SUnitExtensionsTest >> testAutoDenyFalse [

	self assert: self isLogging.
	self 
		should: [ self deny: 1 = 1 description: 'self deny: 1 = 1' ] 
		raise: self defaultTestFailure.
	self 
		assert: (self failureLog contents substrings:  {Character cr}) last 
		equals: 'self deny: 1 = 1'.
	
]

{ #category : 'tests' }
SUnitExtensionsTest >> testAutoDenyTrue [
	self deny: 1 equals: 2.
	self deny: false
]

{ #category : 'tests' }
SUnitExtensionsTest >> testErrorInRaiseWithExceptionDo [
	| testCase testResult |
	testCase := self class selector: #errorInRaiseWithExceptionDoTest.
	testResult := testCase run.

	self assert: (testResult errors includes: testCase).
	self assert: testResult errors size equals: 1.
	self assertEmpty: testResult failures.
	self assertEmpty: testResult passed
]

{ #category : 'tests' }
SUnitExtensionsTest >> testExceptionWithMatchingString [
	self should: [ Object obsolete ] raise: Error whoseDescriptionIncludes: 'NOT obsolete' description: 'tested obsoleting Object'
]

{ #category : 'tests' }
SUnitExtensionsTest >> testExceptionWithoutMatchingString [
	self
		should: [ Object obsolete ]
		raise: Error
		whoseDescriptionDoesNotInclude: 'Zero'
		description: 'tested obsoleting Object'
]

{ #category : 'tests' }
SUnitExtensionsTest >> testInvalidShouldNotTakeMoreThan [
	| testCase testResult |
	testCase := self class selector: #invalidShouldNotTakeMoreThan.
	testResult := testCase run.

	self assertEmpty: testResult passed.
	self assert: testResult failures size equals: 1.
	self assert: (testResult failures includes: testCase).
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testInvalidShouldNotTakeMoreThanMilliseconds [
	| testCase testResult |
	testCase := self class selector: #invalidShouldNotTakeMoreThanMilliseconds.
	testResult := testCase run.

	self assertEmpty: testResult passed.
	self assert: testResult failures size equals: 1.
	self assert: (testResult failures includes: testCase).
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testNoExceptionInShouldRaiseWithExceptionDo [
	| testCase testResult |
	testCase := self class selector: #noExceptionInShouldRaiseWithExceptionDoTest.
	testResult := testCase run.

	self assert: (testResult failures includes: testCase).
	self assert: testResult failures size equals: 1.
	self assertEmpty: testResult passed.
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testNoExceptionWithMatchingString [
	<ignoreNotImplementedSelectors: #(messageNotUnderstoodByObject)>
	self
		shouldnt: [ Object messageNotUnderstoodByObject ]
		raise: MessageNotUnderstood
		whoseDescriptionIncludes: 'Zero'
		description: 'tested obsoleting Object'
]

{ #category : 'tests' }
SUnitExtensionsTest >> testNoExceptionWithNoMatchingString [
	<ignoreNotImplementedSelectors: #(messageNotUnderstoodByObject)>
	self
		shouldnt: [ Object messageNotUnderstoodByObject ]
		raise: MessageNotUnderstood
		whoseDescriptionDoesNotInclude: 'messageNotUnderstoodByObject'
		description: 'tested obsoleting Object'
]

{ #category : 'tests' }
SUnitExtensionsTest >> testShouldFix [
	| testCase testResult |
	testCase := self class selector: #shouldFixTest.
	testResult := testCase run.

	self assert: (testResult passed includes: testCase).
	self assert: testResult passed size equals: 1.
	self assertEmpty: testResult failures.
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testShouldRaiseWithExceptionDo [
	| testCase testResult |
	testCase := self class selector: #shouldRaiseWithExceptionDoTest.
	testResult := testCase run.

	self assert: (testResult passed includes: testCase).
	self assert: testResult passed size equals: 1.
	self assertEmpty: testResult failures.
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testValidShouldNotTakeMoreThan [
	| testCase testResult |
	testCase := self class selector: #validShouldNotTakeMoreThan.
	testResult := testCase run.

	self assert: (testResult passed includes: testCase).
	self assert: testResult passed size equals: 1.
	self assertEmpty: testResult failures.
	self assertEmpty: testResult errors
]

{ #category : 'tests' }
SUnitExtensionsTest >> testValidShouldNotTakeMoreThanMilliseconds [
	| testCase testResult |
	testCase := self class selector: #validShouldNotTakeMoreThanMilliseconds.
	testResult := testCase run.

	self assert: (testResult passed includes: testCase).
	self assert: testResult passed size equals: 1.
	self assertEmpty: testResult failures.
	self assertEmpty: testResult errors
]

{ #category : 'real tests' }
SUnitExtensionsTest >> validShouldNotTakeMoreThan [

	self
		should: [ (Delay forMilliseconds: 100) wait ]
		notTakeMoreThanMilliseconds: 200
]

{ #category : 'real tests' }
SUnitExtensionsTest >> validShouldNotTakeMoreThanMilliseconds [

	self
		should: [ (Delay forMilliseconds: 100) wait ]
		notTakeMoreThanMilliseconds: 200
]
